package com.laker.admin.module.inv.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.laker.admin.module.inv.entity.InvMessage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.laker.admin.module.inv.vo.InvMessageGroupVO;
import com.laker.admin.module.inv.vo.InvStatisticsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author laker
 * @since 2024-03-21
 */
@Mapper
public interface InvMessageMapper extends BaseMapper<InvMessage> {
    int tradeinById(InvMessage entity);

    int tradeoutById(InvMessage entity);

    int invAllCount();

    int selectCountByCommId(@Param("id") Long id);

    // @Select("SELECT IM.comm_name name, SUM(IM.inv_sum) value FROM inv_message IM WHERE IM.DEL_FLAG = 0 GROUP BY IM.comm_id, IM.comm_name ORDER BY IM.comm_id, IM.comm_name")
    @Select("SELECT ct.comm_type_name name, SUM(IM.inv_sum) value\n" +
            "FROM inv_message IM\n" +
            "LEFT JOIN comm_product cp ON im.comm_id = cp.comm_id AND cp.del_flag = 0\n" +
            "LEFT JOIN comm_type ct ON cp.comm_type_id = ct.comm_type_id\n" +
            "WHERE IM.DEL_FLAG = 0\n" +
            "GROUP BY ct.comm_type_id, ct.comm_type_name\n" +
            "ORDER BY ct.comm_type_id, ct.comm_type_name")
    List<InvStatisticsVo> selectRealtimeInv();

    @Select("SELECT DATE_FORMAT(inv_tradeiout_time, '%Y-%m-%d') name, SUM(IM.inv_tradeout_product_sum) value FROM inv_tradeout IM GROUP BY DATE_FORMAT(inv_tradeiout_time, '%Y-%m-%d') ORDER BY DATE_FORMAT(inv_tradeiout_time, '%Y-%m-%d')")
    List<InvStatisticsVo> selectTradeoutInv();

    List<InvMessageGroupVO> selectGroupbyCommList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
}

